<?php

namespace App\Http\Controllers;

use App\Comment;
use App\Discuss;
use App\Http\Requests;
use App\Parsedown;
use App\Study;
use App\Studyfav;
use App\Task;
use App\Judgetask;
use App\User;
use App\Utils;
use Auth;
use Cache;
use Cookie;
use DB;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Input;
use Log;
use Mail;
use Redirect;
use Reponse;
use View;
use Crypt;
use App\Permission;

class judgeController extends Controller
{
    public function __construct()
    {
        //          $this->middleware('auth');
    }
	public function status(Request $request)
	{
		$input=$request->all();
		/*
		if(isset($input['name'])&&strlen($input['name'])>0)
		{
			$name=$input['name'];
			$user=User::where("name","=",$input['name'])->get()->first();
			if($user==null)
				$list=Judgetask::where("taskid","=","146")->orderby("created_at","desc")->paginate(20);
			else
			$list=Judgetask::where("userid","=",$user->id)->orderby("created_at","desc")->paginate(20);
		}
		else*/
		$list=Judgetask::where("taskid","=",146)->orderby("created_at","desc")->paginate(20);
		foreach($list as $l)
		{
			$l->user=User::find($l->userid);
		}

		return View::make("judge.status")->with(compact("list"))->with(compact("name"));
	}
	public function detail(Request $request,$id)
	{
		if(!Auth::check())return "login first";
		$data=Judgetask::find($id);
		//if($data->userid!=Auth::user()->id)return "没有权限";
		if($data->userid!=Auth::user()->id && !Permission::user_is_super(Auth::user()))return "没有权限";
		$arr=json_decode($data->judge_info,true);
		$data['info']=$arr;
		
		return View::make("judge.detail")->with(compact("data"));
	}
}
